package com.service.impl;

import com.dao.Td_tbreadlogDao;
import com.dao.TeamDao;
import com.entity.Td_tbreadlog;
import com.service.inte.StudyServiceInte;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;
import java.util.List;

@Service
public class StudyServiceImpl implements StudyServiceInte {

    @Autowired
    private TeamDao teamDao;
    @Autowired
    private Td_tbreadlogDao readLogDao;

    @Override
    public List<Object[]> getRollByFatherType(int fatherType) {
        return teamDao.getRollByFatherType(fatherType);
    }

    @Override
    public Td_tbreadlog getReadLogByFd_id(int id) {
        return readLogDao.getByFd_id(id);
    }

    @Override
    @Transactional
    public int addReadTotal(int teamId, int loginId) {
        return readLogDao.addReadTotal(teamId,loginId);
    }

    @Override
    public Td_tbreadlog getByTeamId8LoginId(int teamId, int loginId) {
        return readLogDao.getByTeamId8LoginId(teamId,loginId);
    }

    @Override
    public List<Object[]> getThreeTeamByMaxTotal() {
        return readLogDao.getThreeTeamByMaxTotal();
    }

    @Override
    public List<Object[]> getTeamByMaxTotal(int loginId, int page) {
        return readLogDao.getTeamByMaxTotal(loginId, PageRequest.of(page,10));
    }

    @Override
    public List<Object[]> getTeamByTypeDescCreateTime(int loginId, int typeId, int page) {
        return readLogDao.getTeamByTypeDescCreateTime(loginId,typeId,PageRequest.of(page,10));
    }

    @Override
    public int saveReadLog(Td_tbreadlog td_tbreadlog) {
        try {
            readLogDao.save(td_tbreadlog);
            return 1;
        }catch (Exception e){
            return 0;
        }
    }

    @Override
    public List<Object[]> getThreeNew() {
        return readLogDao.getThreeNew();
    }
}
